package com.network;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Spring生命周期测试
 *
 * @author: sun.hongliang
 * @create: 2018/08/31 18:46
 */
public class SpringBeanTest implements ApplicationContextAware,BeanNameAware,BeanFactoryAware,BeanPostProcessor,InitializingBean,DisposableBean {

    private String name;
    private String adderss;
    private String phone;

    //1
    public SpringBeanTest(){
        System.out.println("SpringBeanTest===========");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAdderss() {
        return adderss;
    }

    public void setAdderss(String adderss) {
        this.adderss = adderss;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void init(){
        System.out.println("init...");
    }

    //2 Bean就获得了自己在配置文件中的id
    @Override
    public void setBeanName(String s) {
        System.out.println("setBeanName:" + s);
    }

    //3 Bean就获得了自己所在的BeanFactory
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("beanFactory:" + beanFactory);
    }

    @Override
    public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
        System.out.println("postProcessBeforeInitialization...");
        return o;
    }

    @Override
    public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
        System.out.println("postProcessAfterInitialization...");
        return o;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("destroy");
    }

    public void destoryTest(){
        System.out.println("desttoryTest");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("setApplicationContext");
    }
}
